<?php

declare(strict_types=1);

namespace App\CustHub\Listener;


use App\CustHub\Event\SopNewUserTrigger;
use App\CustHub\Event\SopTagTrigger;
use App\CustHub\Service\ChSopService;
use Hyperf\Event\Annotation\Listener;
use Hyperf\Event\Contract\ListenerInterface;
use Psr\Container\ContainerInterface;


#[Listener]
class SopTagListener implements ListenerInterface
{
    protected $container;

    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;
    }

    public function listen(): array
    {
        // 返回一个该监听器要监听的事件数组，可以同时监听多个事件
        return [
            SopTagTrigger::class
        ];
    }

    /**
     * @param SopTagTrigger $event
     */
    public function process(object $event): void
    {
        // 事件触发后该监听器要执行的代码写在这里，比如该示例下的发送用户注册成功短信等
        // 直接访问 $event 的 user 属性获得事件触发时传递的参数值
        $sopService = $this->container->get(ChSopService::class);
        $sopService -> triggerTagSop($event->contact);
    }

}